#mysql数据库备份
date=$(date +%F_%H-%M-%S)
host=192.168.1.120
db=test
user=root
pass=123456
back_dir=/data/db_backup
sql_file=${db}_full_${date}.sql
back_file=${db}_full_${date}.zip
cd $back_dir
if mysqldump -h$host -p$pass -u$user --single-transaction --routines --triggers -B $db > $sql_file;then
zip $back_file $sql.file && rm -f $sql_file
fi
find $back_dir -name '*.zip' -ctime +14 -exec rm {} \;
